package com.zrx.controller;

import com.zrx.domain.ResponseResult;
import com.zrx.domain.entity.Article;
import com.zrx.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张荣欣
 * @create ：2022/9/14  17:23
 */
@RestController
@RequestMapping("/article")
@Api(tags = "文章")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

//    @GetMapping("/list")
//    @ApiOperation(value = "分页查询", notes = "参数字段说明. ")
//    public List<Article> test(){
//        return articleService.list();
//    }

    /**
     *查询热门文章
     * @return
     */
    @GetMapping("/hotArticleList")
    @ApiOperation(value = "查询热门文章", notes = "查询热门文章 ")
    public ResponseResult hotArticleList(){
        return articleService.hotArticleList();
    }

    /**
     *查询热门文章
     * @return
     */
    @GetMapping("/articlePageList")
    @ApiOperation(value = "文章 分页", notes = "文章 分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "页号"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小"),
            @ApiImplicitParam(name = "categoryId",value = "文章id")
    }
    )
    public ResponseResult articlePageList(Integer pageNum,Integer pageSize,Long categoryId){
        return articleService.articlePageList(pageNum,pageSize,categoryId);
    }

    /**
     *查询文章内容
     * @return
     */
    @GetMapping("/getarticleDetail/{id}")
    @ApiOperation(value = "查询文章内容", notes = "查询文章内容")
    public ResponseResult getarticleDetail(@PathVariable("id") Long id){
        return articleService.getarticleDetail(id);
    }

    /**
     *更新redis浏览记录
     * @return
     */
    @PutMapping("/updateViewCount/{id}")
    @ApiOperation(value = "更新redis浏览记录", notes = "更新redis浏览记录")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }
}
